package com.yuexunit.finance.account.action.v1;

import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.finance.account.action.v1.AccountManagementActionApi;
import com.yuexunit.finance.context.FinanceSessionContext;
import com.yuexunit.finance.member.action.v1.EnterpriseActionApiImpl;
import com.yuexunit.finance.project.entity.lexicon.DefaultAccountEnum;
import com.yuexunit.finance.zhanghuguangli.entity.EnterpriseAccountEntity;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;

@Implements(AccountManagementActionApi.class)
public class AccountManagementActionApiImp implements AccountManagementActionApi {
	public static Logger logger = LoggerFactory.getLogger(EnterpriseActionApiImpl.class);
	
	@Override
	@Transactional
	public void insertAccountManagement(Long enterpriseId, String creditCard, String accountHolder, String subbranch, String depositBank) {
		
		if (null == enterpriseId) {
			if (FinanceSessionContext.isEnterprise()) {
				enterpriseId = FinanceSessionContext.getEnterpriseId();
			}
		}
		
		EnterpriseAccountEntity ee=new EnterpriseAccountEntity();
		ee.setDefaultAccount(DefaultAccountEnum.UNKNOWN);
		Date date = new Date(); 
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//可以方便地修改日期格式
		String dateTime =dateFormat.format(date); 
		ParsePosition pos = new ParsePosition(0);
		Date createDateTime = dateFormat.parse(dateTime, pos);
		ee.setEnterpriseId(enterpriseId);
		ee.setCreditCard(creditCard.replaceAll(" ", ""));
		ee.setAccountHolder(accountHolder);
		ee.setSubbranch(subbranch);
		ee.setDepositBank(depositBank);
		ee.setCreateDateTime(createDateTime);
		PersistUtil.insert(ee);
		logger.info("ee----------------"+ee);
	}

}
